package camera;

/**
 * The Class Camera.
 */
public class Camera {
	
	/**
	 * Instantiates a new camera.
	 *
	 * @param x the x
	 * @param y the y
	 * @param left the left
	 * @param right the right
	 * @param top the top
	 * @param bottom the bottom
	 * @param screenW the screen w
	 * @param screenH the screen h
	 */
	public Camera(int x, int y, int left, int right, int top, int bottom, int screenW, int screenH)
	{
		this.x = x;
		this.y = y;
		this.left = left;
		this.right = right;
		this.top = top;
		this.bottom = bottom;
		this.screenW = screenW;
		this.screenH = screenH;
	}
	
	/**
	 * Center.
	 *
	 * @param _x the _x
	 * @param _y the _y
	 */
	public void center(int _x, int _y) {
		x = _x - screenW / 2;
		y = _y - screenH / 2;
		
		clamp();
	}
	
	/**
	 * Alter x.
	 *
	 * @param a the a
	 */
	public void alterX(int a) {
		x += a;

		clamp();
	}
	
	/**
	 * Alter y.
	 *
	 * @param a the a
	 */
	public void alterY(int a) {
		y += a;
		
		clamp();
	}
	
	/**
	 * Gets the x.
	 *
	 * @return the x
	 */
	public int getX() {
		return x;
	}
	
	/**
	 * Gets the y.
	 *
	 * @return the y
	 */
	public int getY() {
		return y;
	}
	
	/**
	 * Clamp.
	 */
	private void clamp() {
		if (x < left)
			x = left;
		if (x > right)
			x = right;
		if (y < top)
			y = top;
		if (y > bottom)
			y = bottom;
	}
	
	private int x;
	private int y;
	private final int left;
	private final int right;
	private final int top;
	private final int bottom;
	private final int screenW;
	private final int screenH;
}
